/***************************** BEGIN LICENSE BLOCK ***************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/MPL-1.1.html
 
 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the License.
 
 The Original Code is the "EO-SPS Framework".
 
 The Initial Developer of the Original Code is Spotimage S.A.
 Portions created by the Initial Developer are Copyright (C) 2007
 the Initial Developer. All Rights Reserved.
 
 Contributor(s): 
    Alexandre Robin <alexandre.robin@spotimage.fr>
 
******************************* END LICENSE BLOCK ***************************/

package com.spotimage.eosps;

import org.vast.ogc.gml.GMLTimeReader;
import org.vast.ows.OWSException;
import org.vast.ows.sps.SPSException;
import org.vast.ows.swe.SWEResponseReader;
import org.vast.util.TimeInfo;
import org.vast.xml.DOMHelper;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


/**
 * <p><b>Title:</b>
 * GetSensorAvailability Response Reader v2.0
 * </p>
 *
 * <p><b>Description:</b><br/>
 * Used to read a version 2.0 SPS GetSensorAvailability Response into
 * a GetSensorAvailabilityResponse object
 * </p>
 *
 * <p>Copyright (c) 2010</p>
 * @author Alexandre Robin <alexandre.robin@spotimage.fr>
 * @date July, 19 2010
 * @version 1.0
 */
public class GetSensorAvailabilityResponseReaderV20 extends SWEResponseReader<GetSensorAvailabilityResponse>
{
	protected GMLTimeReader gmlReader = new GMLTimeReader();
	
	
	public GetSensorAvailabilityResponse readXMLResponse(DOMHelper dom, Element responseElt) throws OWSException
	{
		try
		{
			GetSensorAvailabilityResponse response = new GetSensorAvailabilityResponse();			
            response.setVersion("2.0");
            
            // read extensions
            readXMLExtensions(dom, responseElt, response);
            
            // responsePeriod
            Element timePeriodElt = dom.getElement(responseElt, "responsePeriod/*");
            TimeInfo responsePeriod = gmlReader.readTimePeriod(dom, timePeriodElt);
            response.setResponsePeriod(responsePeriod);
            
            // list of availabilityPeriod
            NodeList periodElts = dom.getElements(responseElt, "availabilityPeriod/*");
    		for (int i=0; i<periodElts.getLength(); i++)
    		{
    			TimeInfo period = gmlReader.readTimePeriod(dom, ((Element)periodElts.item(i)));
    			response.getAvailabilityPeriods().add(period);
    		}
            
            return response;
		}
		catch (Exception e)
		{
			throw new SPSException(e);
		}
	}	
}
